package org.crazyrunner.common.page;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlTransient;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class PagingSupport<T> {
	private int pageNo =  1;// 当前页
	private int pageSize;// 每页显示记录数
	private int firstNo =  1;//首页
	private int lastNo;//尾页
	private int rowCount;//总记录数
	@SuppressWarnings("unused")
	private boolean firstPage;//第一页
	@SuppressWarnings("unused")
	private boolean lastpage;//最后一页
	private String orderBy;//排序
	private List<T> list = new ArrayList<T>();//数据
	
	public PagingSupport() {
		this.firstNo  =  1;
		this.pageSize = 10;
		this.pageNo   =  1;
	}
	
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		if(pageSize < 10)
			this.pageSize = 10;
		else
			this.pageSize = pageSize;
	}
	
	public int getFirstNo() {
		return firstNo;
	}
	public void setFirstNo(int firstNo) {
		this.firstNo = firstNo;
	}
	
	@JsonIgnore
	@XmlTransient
	public int getLastNo() {
		lastNo = (rowCount / pageSize );
		return lastNo;
	}
	public void setLastNo(int lastNo) {
		this.lastNo = lastNo;
	}
	
	@JsonIgnore
	@XmlTransient
	public int getRowCount() {
		return rowCount;
	}
	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}
	
	@JsonIgnore
	@XmlTransient
	public boolean isFirstPage() {
		return pageNo == firstNo;
	}
	public void setFirstPage(boolean firstPage) {
		this.firstPage = firstPage;
	}
	
	@JsonIgnore
	@XmlTransient
	public boolean isLastpage() {
		return pageNo == lastNo;
	}
	public void setLastpage(boolean lastpage) {
		this.lastpage = lastpage;
	}
	
	@JsonIgnore
	@XmlTransient
	public String getOrderBy() {
		return orderBy;
	}
	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	
	
	/**
	 * 返回分页记录的第一条行号
	 * @return
	 */
	@JsonIgnore
	@XmlTransient
	public int getFirstResult(){
		return pageNo == 1 ? 1:(pageSize*pageNo)-1;
	}
	
	
}
